package io.renren.modules.usian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.renren.modules.usian.entity.CollegeEntity;
import io.renren.modules.usian.service.CollegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.usian.dao.TeacherDao;
import io.renren.modules.usian.entity.TeacherEntity;
import io.renren.modules.usian.service.TeacherService;


@Service("teacherService")
public class TeacherServiceImpl extends ServiceImpl<TeacherDao, TeacherEntity> implements TeacherService {

    @Autowired
    private TeacherDao teacherDao;

    @Autowired
    private CollegeService collegeService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TeacherEntity> page = this.page(
                new Query<TeacherEntity>().getPage(params),
                new QueryWrapper<TeacherEntity>()
        );
        List<TeacherEntity> list = page.getRecords();
        /*
            filter:过滤
            map:数据的再处理
            sorted:排序
            collect:返回数据的类型
         */
        list.stream().map((teacher)->{
            CollegeEntity college = collegeService.getById(teacher.getCid());
            teacher.setCname(college.getName());
            return teacher;
        }).collect(Collectors.toList());


//        for (int i = 0; i < list.size(); i++) {
//            TeacherEntity teacher = list.get(i);
//            CollegeEntity college = collegeService.getById(teacher.getCid());
//            teacher.setCname(college.getName());
//        }

        return new PageUtils(page);
    }
    /*
    根据方向来获取所有的项目经理列表
     */
    @Override
    public List<TeacherEntity> showListByCid(int cid,int role) {
        LambdaQueryWrapper<TeacherEntity> query = new LambdaQueryWrapper<TeacherEntity>();
        //按照学院查
        query.eq(TeacherEntity::getCid,cid);
        //按照角色为4的查
        query.eq(TeacherEntity::getRole,role);
        //在职的查
        query.eq(TeacherEntity::getStatus,0);
        List<TeacherEntity> list = teacherDao.selectList(query);
        return list;
    }

//    @Override
//    public List<TeacherEntity> showHListByCid(int cid) {
//        LambdaQueryWrapper<TeacherEntity> query = new LambdaQueryWrapper<TeacherEntity>();
//        //按照学院查
//        query.eq(TeacherEntity::getCId,cid);
//        //按照角色为4的查
//        query.eq(TeacherEntity::getRole,3);
//        //在职的查
//        query.eq(TeacherEntity::getStatus,0);
//        List<TeacherEntity> list = teacherDao.selectList(query);
//        return list;
//    }

}